/**
 * 客户列表
*/

var player_item = new Object({
    table:null,
    init:function(){
        if(null != this.table)
            return;
        this.queryInfo();
    },
    queryInfo:function(){
        this.table = $('#tb_player_item').bootstrapTable({
            url: contextPath + '/player/item/listData.json',
            responseHandler: function (res) {
                return res.data;
            },
            queryParams: function (params) {
                return params;
            },
            pagination: true,
            pageList: '[10,20, 50, 100]',
            //showColumns: true,
            showRefresh: true,
            showToggle: true,
            //showPaginationSwitch:true,
            sidePagination: 'server',
            //striped:true,
            sortable: false,
            height: 700,
            search: true,
            searchAlign: 'left',
          /*  toolbar: '<div style="float: left;margin-right:5px;">' +
            '    <button class="btn btn-default" type="button" onclick="agent_mg.add()">' +
            '        <i style="margin-right:2px;" class="fa fa-search"></i>' +
            '        <span>新增</span>' +
            '    </button>' +
            '</div>',*/
            idField: 'id',
            uniqueId: 'id',
            //singleSelect: true,
            clickToSelect: true,
            columns: [{
                field: 'registerTime',
                title: '注册时间',
                align: 'center',
                width: 100,
                formatter: function (value, row, index) {
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm")
                }
            }, {
                field: 'nickname',
                title: '昵称',
                width: 100
            }, {
                field: 'openId',
                title: 'OpenId',
                width: 100,
                visible:false
            }, {
                field: 'playerItem.id',
                title: 'item_id',
                width: 60,
                visible:false
            }, {
                field: 'playerItem.itemNum',
                title: '金币',
                width: 60
            },{
                field: 'op',
                title: '操作',
                align: 'center',
                width: 100,
                formatter: function (value, row, index) {
                    var strHtml = '';
                        //strHtml += '<a href="javascript:void(0);" onclick="client_list.edit('+row.id+',\''+row.name+'\','+row.ratio+')">编辑</a>&nbsp;&nbsp;';
                    strHtml = '<div class="btn-group">' +
                    '<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">更多<i class="fa fa-caret-down"></i></button>' +
                    '   <ul class="dropdown-menu">'+
                    '       <li><a href="javascript:void(0);" onclick="player_item.recharge('+row.playerItem.id+',\''+row.nickname+'\','+row.playerItem.itemNum+')">充值</a></li>'+
                    //'       <li><a href="javascript:void(0);" onclick="">重置财务信息</a></li>'+
                    '   </ul>'+
                    '</div>'
                    return strHtml;
                }
            }]
        });
        $('.search input').attr("placeholder", "微信昵称");
    },
    recharge:function(itemId,nickname,itemNum){
        var rechargeModal = '<div id="rechargeModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">'+
            '   <div class="modal-dialog">'+
            '       <div class="modal-content">'+
            '           <div class="modal-header">'+
            '               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'+
            '               <h4 class="modal-title">'+nickname+':充值金币</h4>'+
            '           </div>'+
            '           <div class="modal-body">' +
            '               <form class="form-horizontal" id="rechargeForm">'+
            '                   <div class="form-group">'+
            '                       <label class="col-sm-3 control-label">账户金币：</label>'+
            '                       <div class="col-sm-9">'+
            '                           '+ itemNum +
            '                       </div>'+
            '                   </div>'+
            '                   <div class="form-group">'+
            '                       <label class="col-sm-3 control-label">充值金币：</label>'+
            '                       <div class="col-sm-9" style="padding-top:7px;">' +
            '                          <input type="hidden" name="id" value="'+itemId+'">'+
            '                           <input type="text" class="form-control" name="itemNum" value="" />'+
            '                       </div>'+
            '                   </div>'+
            '                   <div class="form-group">'+
            '                       <label class="col-sm-3 control-label">备注：</label>'+
            '                       <div class="col-sm-9" style="padding-top:7px;">'+
            '                           <input type="text" class="form-control" name="description" value="" />'+
            '                       </div>'+
            '                   </div>'+
            '               </form>'+
            '           </div>' +
            '           <div class="modal-footer" style="text-align:center">'+
            '               <button type="button" class="btn btn-primary"  onclick="player_item.rechargeSubmit()" >充值</button>'+
            '               <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
            '           </div>'+
            '       </div>'+
            '   </div>'+
            '</div>';

        /**
         * 添加html中，隐藏
         */
        document.body.appendChild($(rechargeModal)[0]);
        $('#rechargeModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#rechargeModal')[0]);
        });
        //player_item.queryInfo();
        //显示
        $("#rechargeModal").modal('show')
    },
    rechargeSubmit:function(){
        $.ajax({
            url:contextPath+'/player/item/manualRecharge',
            data:$('#rechargeForm').serializeArray(),
            success:function(res){

                alert_message('充值成功');
            },
            error:function(){
                alert_message('充值错误，请联系管理员');
            }
        });
        player_item.table.bootstrapTable('refresh');
        //显示
        $("#rechargeModal").modal('hide')
    }
});